/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * GUIServer.java
 *
 * Created on Mar 2, 2012, 8:17:51 PM
 */
package GUI;

import Controller.Controller;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author gianmariospacagna
 */
public class GUIServer extends javax.swing.JFrame {
    private Controller controller;

    /** Creates new form GUIServer */
    public GUIServer(Controller controller) {
        initComponents();
        this.controller=controller;
    }

    
    
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButtonStartServer = new javax.swing.JButton();
        jButtonStopServer = new javax.swing.JButton();
        jButtonStartFetcher = new javax.swing.JButton();
        jButtonStopFetcher = new javax.swing.JButton();
        jTextFieldPort = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jButtonStartServer.setText("Start");
        jButtonStartServer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonStartServerActionPerformed(evt);
            }
        });

        jButtonStopServer.setText("Stop");
        jButtonStopServer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonStopServerActionPerformed(evt);
            }
        });

        jButtonStartFetcher.setText("Start");
        jButtonStartFetcher.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonStartFetcherActionPerformed(evt);
            }
        });

        jButtonStopFetcher.setText("Stop");
        jButtonStopFetcher.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonStopFetcherActionPerformed(evt);
            }
        });

        jTextFieldPort.setText("2012");

        jLabel1.setText("Listening Port");

        jLabel2.setText("Server");

        jLabel3.setText("Fetcher");

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(42, 42, 42)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                .add(jButtonStartServer)
                                .add(jButtonStopServer))
                            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                .add(jLabel1)
                                .add(jTextFieldPort, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))))
                    .add(layout.createSequentialGroup()
                        .add(62, 62, 62)
                        .add(jLabel2)))
                .add(65, 65, 65)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jButtonStopFetcher)
                    .add(jButtonStartFetcher)
                    .add(jLabel3))
                .addContainerGap(131, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                .add(37, 37, 37)
                .add(jLabel1)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jTextFieldPort, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 66, Short.MAX_VALUE)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel2)
                    .add(jLabel3))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jButtonStartServer)
                    .add(jButtonStartFetcher))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jButtonStopServer)
                    .add(jButtonStopFetcher))
                .add(60, 60, 60))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButtonStartServerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonStartServerActionPerformed
        try {
            // TODO add your handling code here:
            controller.startServer(jTextFieldPort.getText());
        } catch (IOException ex) {
            Logger.getLogger(GUIServer.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_jButtonStartServerActionPerformed

    private void jButtonStopServerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonStopServerActionPerformed
        try {
            // TODO add your handling code here:
            controller.stopServer();
        } catch (IOException ex) {
            Logger.getLogger(GUIServer.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_jButtonStopServerActionPerformed

    private void jButtonStartFetcherActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonStartFetcherActionPerformed
        // TODO add your handling code here:
        controller.startFetcher();
    }//GEN-LAST:event_jButtonStartFetcherActionPerformed

    private void jButtonStopFetcherActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonStopFetcherActionPerformed
        // TODO add your handling code here:
        controller.stopFetcher();
    }//GEN-LAST:event_jButtonStopFetcherActionPerformed

    /**
     * @param args the command line arguments
     */
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonStartFetcher;
    private javax.swing.JButton jButtonStartServer;
    private javax.swing.JButton jButtonStopFetcher;
    private javax.swing.JButton jButtonStopServer;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JTextField jTextFieldPort;
    // End of variables declaration//GEN-END:variables
}
